package com.andyage.admin.action;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.andyage.admin.bean.AdattentionBean;
import com.andyage.admin.bean.RoleMenuBean;
import com.andyage.admin.bean.UtilBean;
import com.andyage.admin.service.IRoleMenuService;
import com.andyage.util.TypeTransfor;
import com.google.gson.Gson;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

@Controller
@RequestMapping("/admin")
public class RoleMenuAction {
	@Resource
	private IRoleMenuService iroleMenuService;
	public String CONTENT_TYPE = "text/html;charset=utf-8";

	@RequestMapping("/insertRoleMenuInfoBybatch")
	public void insertRoleMenuInfoBybatch(HttpServletResponse response, HttpServletRequest request) throws Exception {
		String menuId =request.getParameter("menuId");
		String roleId=request.getParameter("roleId");//身份表的id
		System.out.println(menuId);
		JSONArray jsonArray = JSONArray.fromObject(menuId);
		 Iterator<Object> it = jsonArray.iterator();
		 List<RoleMenuBean> list=new ArrayList<RoleMenuBean>();
		 while (it.hasNext()){
			 JSONObject ob = (JSONObject) it.next();
			 RoleMenuBean bean = new RoleMenuBean();
             if(ob.getString("id")!=null){
            	 bean.setMenuId(Integer.valueOf(ob.getString("id")));
             }
             if(ob.getString("ch")!=null&&!"".equals(ob.getString("ch"))){
            	 bean.setButtonId(ob.getString("ch"));
             }
             if(roleId!=null&&!"".equals(roleId)){
            	 bean.setRoleId(Integer.valueOf(roleId));
             }
             if(bean!=null){
                 list.add(bean);
             }
		 }
		 String json = iroleMenuService.insertRoleMenuInfoBybatch(list);
			response.setContentType(CONTENT_TYPE);
			response.getWriter().print(json);
	}
	@RequestMapping("/queryRoleMenuInfoByroleId")
	public void queryRoleMenuInfoByroleId(RoleMenuBean roleMenu, HttpServletResponse response) throws Exception {
		String json = iroleMenuService.queryRoleMenuInfoByroleId(roleMenu);
		response.setContentType(CONTENT_TYPE);
		response.getWriter().print(json);
	}
	@RequestMapping("/deleteRoleMenuByRoleId")
	public void deleteRoleMenuByRoleId(RoleMenuBean roleMenu, HttpServletResponse response) throws Exception {
		String json = iroleMenuService.deleteRoleMenuByRoleId(roleMenu);
		response.setContentType(CONTENT_TYPE);
		response.getWriter().print(json);
	}
}
